<?php

namespace Biz\service\advertisement\spotlight;

class SpotlightActivityService
{
    private static $instance;
    private SpotlightActivity $activity;

    public static function getActivity($p = 1, $uid = 0): SpotlightActivity
    {
        switch ($p) {
            case 3:
                $conf = SpotlightConfig::p3($uid);
                break;
            case 2:
                $conf = SpotlightConfig::p2($uid);
                break;
            case 1:
                $conf = SpotlightConfig::p1($uid);
                break;
            default:
                $conf = SpotlightConfig::p($p, $uid);
        }
        return new SpotlightActivity($conf);
    }

    public static function getInstance($p = 1, $uid = 0): SpotlightActivityService
    {
        if (!self::$instance) {
            self::$instance = new self();
            self::$instance->activity = self::getActivity($p, $uid);
        }
        return self::$instance;
    }


    public function main(): array
    {
        return [
            'brand_card' => $this->activity->brandCard(),
            'release_time_format' => date("Y-m-d H:i:s", $this->activity->releaseTime()),
            'release_time' => $this->activity->releaseTime(),
            'is_subscribe' => $this->activity->isSubscribe(),
            'is_guess' => $this->activity->isGuess(),
            'tips' => $this->activity->tips(),
            'guess_rank' => $this->activity->guessRank(),
            'guess_labels' => $this->activity->guessLabels(),
            'uid' => $this->activity->getUid(),
            'elements' => $this->activity->getElements(),
        ];
    }

    public function publishPage(): array
    {
        return [
            'brand_card' => $this->activity->brandCard(),
            'wiki_card' => $this->activity->wikiCard(),
            'features' => $this->activity->likedFeatures(),
            'is_open' => $this->activity->isOpen(),
            'is_subscribe' => $this->activity->isNextSubscribe(),
            'winners' => $this->activity->winners(),
            'barrage' => $this->activity->barrage(),
            'topic_id' => $this->activity->topicId(),
            'topic_title' => \Doraemon\model\TopicActivity::getById($this->activity->topicId(), 'title'),
            'live_card' => $this->activity->liveCard(),
            'room_id' => $this->activity->getRoomId(),
            'uid' => $this->activity->getUid(),
            'elements' => $this->activity->getPublishElements(),
        ];
    }

    public function guess($keywords)
    {
        return $this->activity->guess($keywords);
    }

    public function open()
    {
        return $this->activity->open();
    }

    public function likeFeatures($features)
    {
        return $this->activity->likeFeatures($features);
    }

    public function subscribe()
    {
        return $this->activity->subscribe();
    }

    public function nextSubscribe()
    {
        return $this->activity->nextSubscribe();
    }

    public function notePool($page)
    {
        return $this->activity->notePool($page);
    }

}